
<!-- 张梦莉  2017-11-02 售后管理（申请中）-->

<template>
    <section>
        <!--工具条-->
        <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
            <el-form :inline="true" :model="filters">
                <el-form-item>
                    <el-input v-model="filters.order_id" placeholder="订单号"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="success" v-on:click="getgoodslist">查询</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handleAdd">新增</el-button>
                </el-form-item>
            </el-form>
        </el-col>

        <!--列表-->
        <el-table :data="goodslists" highlight-current-row v-loading="listLoading" border @selection-change="selsChange" style="width: 100%;">
            <!--<el-table-column type="selection" width="55">
            </el-table-column>-->
            <el-table-column prop="id" label="订单号" sortable>
            </el-table-column>
            <el-table-column prop="customer_name" label="客户名称">
            </el-table-column>
            <el-table-column prop="order_status" label="状态">
            </el-table-column>
            <el-table-column prop="totalprice" label="总计" sortable>
            </el-table-column>
            <el-table-column prop="creattime" label="生成日期" sortable>
            </el-table-column>
            <el-table-column prop="updatetime" label="修改日期" >
            </el-table-column>
            <el-table-column prop="process" label="售后流程" :formatter="formatstatus">
            </el-table-column>
            <el-table-column label="操作" width="150">
                <template slot-scope="scope">
                    <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                    <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!--工具条-->
        <el-col :span="24" class="toolbar">
            <!--<el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>-->
            <el-pagination layout="total, sizes, prev, pager ,next" :page-size="filters.pageSize" @current-change="handleCurrentChange" @size-change="handleSizeChange" :total="total" style="float:right;">
            </el-pagination>
        </el-col>

        <!--新增界面-->
        <el-dialog title="新增" v-model="addFormVisible" :close-on-click-modal="false">
            <el-form :model="addForm" label-width="80px" :rules="addFormRules" ref="addForm">
                <el-form-item label="客户名称" prop="customer_name">
                    <el-input v-model="addForm.customer_name" auto-complete="off" ></el-input>
                </el-form-item>
                <el-form-item label="订单状态" prop="ordeer_status">
                    <el-input v-model="addForm.ordeer_status" ></el-input>
                </el-form-item>
                <el-form-item label="商品数量" prop="goods_number">
                    <el-input v-model="addForm.goods_number" ></el-input>
                </el-form-item>
                <el-form-item label="" prop="totalprice">
                    <el-input type="textarea" v-model="addForm.goods_explain"></el-input>
                </el-form-item>
                <el-form-item label="订单状态" prop="order_status" >
                    <el-radio-group v-model="addForm.order_status">
                        <el-radio class="radio" :label="5">上架</el-radio>
                        <el-radio class="radio" :label="4">上架</el-radio>
                        <el-radio class="radio" :label="3">上架</el-radio>
                        <el-radio class="radio" :label="2">上架</el-radio>
                        <el-radio class="radio" :label="1">上架</el-radio>
                        <el-radio class="radio" :label="0">下架</el-radio>
                    </el-radio-group>
                </el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="addFormVisible = false">取消</el-button>
                <el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
            </div>
        </el-dialog>
    </section>
</template>

<script>
    import util from '../../common/js/util'
    //import NProgress from 'nprogress'
    import {} from '../../api/api';

    export default {
        data() {
            return {
                filters: {
                    order_id: '',
                    pageSize: '10'
                },

                total: 0,
                page: 1,
                listLoading: false,
                sels: [],//列表选中列

                editFormVisible: false,//编辑界面是否显示
                editLoading: false,
                editFormRules: {
                    goods_name: [
                        { required: true, message: '请输入姓名', trigger: 'blur' }
                    ]
                },

                addFormVisible: false,//新增界面是否显示
                addLoading: false,
                addFormRules: {
                    goods_name: [
                        { required: true, message: '请输入姓名', trigger: 'blur' }
                    ]
                },
                //新增界面数据
                addForm: {
                    goods_name: "",
                    goods_img: "",
                    goods_number: "1",
                    goods_price:"",
                    goods_status:1,
                    goods_explain:"",
                    classProps:{},
                    brand_id:null,
                    class_id:null,
                },
                fenxiaoList: [],
                timeout: null,

            }
        },
        computed: {
        },
        methods: {
            //商品状态转换
            formatstatus: function (row, column) {
                return row.goods_status == 1 ? '已上架' : row.goods_status == 0 ? '已下架' : '未知';
            },
            handleCurrentChange(val) {
                this.page = val;
                this.getgoodslist();
            },
            //条数改变
            handleSizeChange(size) {
                this.filters.pageSize = size;
                this.getgoodslist();
            },
            //获取服务器列表
            getgoodslist() {
                let para = {
                    page: this.page,
                };
                this.listLoading = true;
                //NProgress.start();
                getGoodsList(para).then((res) => {
                    this.total = res.totalCount;
                    this.goodslists = res;
                    this.listLoading = false;
                    //NProgress.done();
                });
            },
            //删除
            handleDel: function (index, row) {
                this.$confirm('确认删除该记录吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    //NProgress.start();
                    deleteGoods(row.id).then((res) => {
                        this.listLoading = false;
                        //NProgress.done();
                        this.$message({
                            message: '删除成功',
                            type: 'success'
                        });
                        this.getgoodslist();
                    });
                }).catch(() => {

                });
            },
            //显示编辑界面
            handleEdit: function (index, row) {
                this.editFormVisible = true;
                this.editForm = Object.assign({}, row);
            },
            //显示新增界面
            handleAdd: function () {
                this.addFormVisible = true;
                this.addForm = {
                    goods_name: "",
                    goods_img: "",
                    goods_number: "1",
                    goods_price:"",
                    goods_status:0,
                    goods_explain:"",
                    classProps: {
                        value: "class_id",
                        label: "class_name",
                        children: "children"
                    }
                };
              this.handleClassOption();
              getBrandList({}).then(res => {
                    this.brands = res.data;
              })
            },
            //编辑
            editSubmit: function () {
                this.$refs.editForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {}).then(() => {
                            this.editLoading = true;
                            //NProgress.start();
                            let para = Object.assign({}, this.editForm);
                            editGoods(para).then((res) => {
                                this.editLoading = false;
                                //NProgress.done();
                                this.$message({
                                    message: '提交成功',
                                    type: 'success'
                                });
                                this.$refs['editForm'].resetFields();
                                this.editFormVisible = false;
                                this.getgoodslist();
                            });
                        });
                    }
                });
            },
            //新增
            addSubmit: function () {
                this.$refs.addForm.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {}).then(() => {
                            this.addLoading = true;
                            //NProgress.start();
                            let para = Object.assign({}, this.addForm);

                            addGoods(para).then((res) => {
                                this.addLoading = false;
                                //NProgress.done();
                                this.$message({
                                    message: '提交成功',
                                    type: 'success'
                                });
                                this.$refs['addForm'].resetFields();
                                this.addFormVisible = false;
                                this.getgoodslist();
                            });
                        });
                    }
                });
            },
            //获取品牌列表
            handleClassChange(options) {
                let id = 0;
                if (options.length === 1) {
                    id = options[0];
                    getClassList({parent_id: id}).then(res => {
                        let options = res.data;
                        for (let x in options) {
                            options[x].children = [];
                        }
                        for (let x in  this.classOptions) {
                            if (this.classOptions[x].class_id === id) {
                                this.classOptions[x].children = options;
                                break;
                            }
                        }
                    });
                } else {
                    let rid = options[0];
                    id = options[1];
                    getClassList({parent_id: id}).then(res => {
                        let allOptions = this.classOptions;
                        for (let x in  allOptions) {
                            if (allOptions[x].class_id === rid) {
                                for (let y in allOptions[x].children) {
                                    if (allOptions[x].children[y].class_id === id) {
                                        allOptions[x].children[y].children = res.data;
                                    }
                                }
                            }
                        }
                    });
                }
            },
           handleClassOption() {
             getClassList({class_level: 1}).then(res => {
                let classOptions = res.data;
                console.log(classOptions);
                for (let x in  res.data) {
                    classOptions[x].children = [];
                }
                this.classOptions = classOptions;
            })
        },

        },
        mounted() {
            this.getgoodslist();
//			console.log(this.$store.getters.getCount)
        },
        watch: {

        }
    }

</script>

<style scoped>

</style>
